package com.lanyan.system.service.impl;

import java.util.List;
import java.util.stream.Collectors;
        import com.lanyan.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.lanyan.common.utils.StringUtils;
import com.lanyan.system.mapper.SkuNameMapper;
import com.lanyan.system.domain.SkuName;
import com.lanyan.system.domain.vo.SkuNameVo;
import com.lanyan.system.service.ISkuNameService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 规格名Service业务层处理
 *
 * @author lanyan
 * @date 2024-11-26
 */
@Service
public class SkuNameServiceImpl  extends ServiceImpl<SkuNameMapper,SkuName> implements ISkuNameService

{
    @Autowired
    private SkuNameMapper skuNameMapper;

    /**
     * 查询规格名
     *
     * @param skuNameId 规格名主键
     * @return 规格名
     */
    @Override
    public SkuName selectSkuNameBySkuNameId(Long skuNameId)
    {
        return this.getById(skuNameId);
    }

    /**
     * 查询规格名Vo列表
     *
     * @param skuName 规格名
     * @return 规格名
     */
    @Override
    public List<SkuNameVo> selectSkuNameVoList(SkuName skuName)
    {
        return selectSkuNameList(skuName)
                .stream()
                .map(x -> (SkuNameVo)x)
                .collect(Collectors.toList());
    }
    /**
     * 查询规格名列表
     *
     * @param skuName 规格名
     * @return 规格名
     */
    @Override
    public List<SkuName> selectSkuNameList(SkuName skuName)
    {
        LambdaQueryChainWrapper<SkuName> wrapper = this.lambdaQuery().eq(SkuName::getDelFlag,"0");
        if (skuName.getProductId() != null) {
            wrapper.eq(SkuName::getProductId, skuName.getProductId());
        }
        if (StringUtils.isNotEmpty(skuName.getName())) {
            wrapper.like(SkuName::getName, skuName.getName());
        }
        return wrapper.list();
    }

        /**
         * 新增规格名
         *
         * @param skuName 规格名
         * @return 结果
         */
    @Override
        public boolean insertSkuName(SkuName skuName)
        {
                    skuName.setCreateTime(DateUtils.getNowDate());
                return this.save(skuName);
        }

        /**
         * 修改规格名
         *
         * @param skuName 规格名
         * @return 结果
         */
    @Override
        public boolean updateSkuName(SkuName skuName)
        {
                    skuName.setUpdateTime(DateUtils.getNowDate());
            return this.updateById(skuName);
        }

        /**
         * 批量删除规格名
         *
         * @param skuNameIds 需要删除的规格名主键
         * @return 结果
         */
    @Override
        public boolean deleteSkuNameBySkuNameIds(Long[] skuNameIds)
        {
            return this.lambdaUpdate().set(SkuName::getDelFlag,"1").in(SkuName::getSkuNameId,skuNameIds).update();
        }

        /**
         * 删除规格名信息
         *
         * @param skuNameId 规格名主键
         * @return 结果
         */
    @Override
        public boolean deleteSkuNameBySkuNameId(Long skuNameId)
        {
            return this.lambdaUpdate().set(SkuName::getDelFlag,"1").eq(SkuName::getSkuNameId,skuNameId).update();
        }
    }
